using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Elementum
{
    class MenuStage : Stage
    {
        Image _backGround0, _backGround1;
        FocusTarget _foucs;
        float cout = 0;
        float fcout = GameClass.RandomBetween(3, 5);

        public MenuStage(Game game)
            : base(game)
        {
        }

        public override void PressedBackButton()
        {
            //base.MenuState();
            GameClass.IsExit = true;
        }

        private void hh() {
            LockTouch = false;
        }

        public override void InitializeScenes()
        {
            Animation ani = new Animation("images/system/black", new Point(820, 500));
            Transition tra = new AlphaTransition(ani, 1, 0, 0, 30);
            tra.Register(this);
            LockTouch =true;
            tra.TransitionDoneAction += hh;

            //Transition tra = new DefauldTransition(1, 0, 0, 60);
            //tra.Register(this);

            _foucs = new FocusTarget(new Vector2(400, 240));

            camera = new Camera2D(this.Game);
            camera.Position = new Vector2(400, 240);
            camera.Focus = _foucs;
            camera.MoveSpeed = 0.16f;

           _stageMenu = new MainMenu(this);
           _controls.Add(_stageMenu);

            Animation background = new Animation("images/stages/root/root0");
            _backGround0 = new Image(background);
            _backGround0.Alpha = 1;
            _backGround0.Position = new Vector2(400-500, 240);

            background = new Animation("images/stages/root/root1");
            _backGround1 = new Image(background);
            _backGround1.Alpha = 1;
            _backGround1.Position = _backGround0.Position + new Vector2(1024, 0);

            actors.Add(_backGround0);
            actors.Add(_backGround1);
            //StageManager.Initialize();

        }

        public override Stage Clone()
        {
            MenuStage stage = new MenuStage(Game);
            stage.InitializeScenes();
            return stage;
        }

        public override void OnDraw(SpriteBatch spriteBatch, int delta)
        {
            base.OnDraw(spriteBatch, delta);
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera.Transform);
            foreach (VisibleObject b in actors)
                b.OnDraw(spriteBatch, camera.Transform);
            spriteBatch.End();
        }

        public override void Update(int delta)
        {
            base.Update(delta);

            cout += 0.02f;

            if(cout>=fcout){
                Vector2 centerPos = new Vector2(400, 240);
                Vector2 offset = new Vector2(GameClass.RandomBetween(-300f, 300f), GameClass.RandomBetween(-200f, 200f));
                _foucs.Position = centerPos += offset;
                cout = 0;
                fcout = GameClass.RandomBetween(5, 8);
            }


            //camera.Position += new Vector2(_speed*(float)Math.Cos(_angle),_speed*(float)Math.Sin(_angle));
            
        }


    }
}
